﻿using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;

namespace HDJ.Framework.Core
{
    public static class LanguageUtils
    {
        public const string SaveFilePathDir = "Assets/Resources/Configs/LocalizedLanguageConfig/";
        public static string LanguageNameToLocalizeName(string langName)
        {

            switch (langName)
            {
                case "Afrikaans":
                    return "Afrikaans";
                case "Arabic":
                    return "العربية";
                case "Basque":
                    return langName;
                case "Belarusian":
                    return "Belarusian";
                case "Bulgarian":
                    return "Български";
                case "Catalan":
                    return "Català";
                case "Czech":
                    return "Čeština";
                case "Danish":
                    return "danske";
                case "Dutch":
                    return "De Nederlandse";
                case "English":
                    return "English";
                case "Estonian":
                    return "eesti";
                case "Faroese ":
                    return langName;
                case "Finnish":
                    return "suomen";
                case "French":
                    return "le français";
                case "German":
                    return "deutsche";
                case "Greek":
                    return "Οι Έλληνες";
                case "Hebrew":
                    return langName;
                case "Hungarian":
                    return "magyar";
                case "Icelandic":
                    return langName;
                case "Indonesian ":
                    return "English";
                case "Italian":
                    return "italiano";
                case "Japanese":
                    return "日本語";
                case "Korean":
                    return "한국";
                case "Latvian":
                    return langName;
                case "Lithuanian":
                    return langName;
                case "Norwegian":
                    return langName;
                case "Polish":
                    return "polskie";
                case "Portuguese":
                    return "Português";
                case "Romanian":
                    return "română";
                case "Russian":
                    return "в россии";
                case "Serbo-Croatian":
                    return langName;
                case "Slovak":
                    return "slovaška";
                case "Slovenian":
                    return langName;
                case "Spanish":
                    return "Español";
                case "Swedish":
                    return "svenska";
                case "Thai":
                    return "ไทย";
                case "Turkish":
                    return langName;
                case "Ukrainian":
                    return langName;
                case "Vietnamese":
                    return "Việt Nam";
                case "ChineseSimplified":
                    return "简体中文";
                case "ChineseTraditional":
                    return "繁體中文";
                case "Chinese":
                    return "中文";

            }
            return langName;
        }

        

        public static SystemLanguage String2SystemLanguage(string c)
        {
            return (SystemLanguage)Enum.Parse(typeof(SystemLanguage), c);
        }

        public static List<string> GetAllFullKeys(SystemLanguage languageName)
        {
            string pathDir = SaveFilePathDir + languageName;
            string[] names = PathUtils.GetDirectoryFileNames(pathDir, new string[] { ".txt" }, false, false);
            List<string> keys = new List<string>();
            foreach (var file in names)
            {
                int index = file.IndexOf('_');
                string temp = file.Remove(0, index + 1);

                string path = temp.Replace('@', '/');

                TableData tableData = TableManager.GetTableData(file);
                foreach (var line in tableData.datas.Values)
                {
                    string key = path + "/" + line[LanguageManager.LanTableKey];
                    string value = line[LanguageManager.LanTableValue].ToString();
                    keys.Add(key);
                }
            }
            return keys;
           
        }

        public static List<string> LoadLangusgeAllFileNames(SystemLanguage languageName)
        {
            string pathDir = SaveFilePathDir  + languageName;
            string[] names = PathUtils.GetDirectoryFileNames(pathDir, new string[] { ".txt" }, false, false);
            List<string> ps = new List<string>();
            foreach (var file in names)
            {
                int index = file.IndexOf('_');
                string temp = file.Remove(0, index + 1);

                string path = temp.Replace('@', '/');
                //Debug.Log("Create Path :" + path);
                ps.Add(path);
            }
            return ps;
        }

    }
}
